package ar.com.personalTravellers.rowProcessors;

import ar.com.personalTravellers.beans.Room;

import com.angel.common.helpers.StringHelper;
import com.angel.io.exceptions.InvalidRowDataException;
import com.angel.io.parameters.ParametersService;
import com.angel.io.processors.commands.imports.ImportRowProcessorCommand;
import com.angel.io.type.rows.ImportRowFile;
import com.angel.io.type.rows.impl.HeaderRowFile;

/**
 *
 * @author William
 */
public class RoomRowProcessorCommand implements ImportRowProcessorCommand {

    public static final String CLIENT_PRICE_COLUMN = "clientPrice";
	public static final String CORPORATIVE_PRICE_COLUMN = "corporativePrice";
	public static final String MAXIMUM_CAPACITY_COLUMN = "maximumCapacity";
    public static final String NAME_COLUMN = "name";
    public static final String OFICIAL_PRICE_COLUMN = "oficialPrice";
    public static final String DESCRIPTION_COLUMN = "description";

    /** DAO Parameter.*/
    public static final String DAO_FACTORY_PARAMETER = "daoFactory";

    

    public void checkRowData(ImportRowFile importRowFile, HeaderRowFile headerRowFile) throws InvalidRowDataException {
        Double clientPrice = importRowFile.getDoubleValue(headerRowFile.getColumnPosition(CLIENT_PRICE_COLUMN));
        Double corporativePrice = importRowFile.getDoubleValue(headerRowFile.getColumnPosition(CORPORATIVE_PRICE_COLUMN));
        Double oficialPrice = importRowFile.getDoubleValue(headerRowFile.getColumnPosition(OFICIAL_PRICE_COLUMN));
        Integer maximumCapacity = importRowFile.getIntegerValue(headerRowFile.getColumnPosition(MAXIMUM_CAPACITY_COLUMN));
        String name = importRowFile.getStringValue(headerRowFile.getColumnPosition(NAME_COLUMN));
		String roomDescription = importRowFile.getStringValue(headerRowFile.getColumnPosition(DESCRIPTION_COLUMN));

		if(clientPrice == null || corporativePrice == null || oficialPrice == null
                || maximumCapacity == null || StringHelper.isEmpty(name) || StringHelper.isEmpty(roomDescription)){
			throw new InvalidRowDataException("Some row data are NULL - " +
					"ClientPrice: [" + clientPrice + "] - " +
                    "CorporativePrice: [" + corporativePrice + "] - " +
                    "OficialPrice: [" + oficialPrice + "] - " +
                    "MaximumCapacity: [" + maximumCapacity + "] - " +
                    "Name: [" + name + "] - " +
                    "RoomDescription: [" + roomDescription + "] - ");
		}
    }

    public Object processRow(ImportRowFile importRowFile, HeaderRowFile headerRowFile, ParametersService parametersService) {
        Double clientPrice = importRowFile.getDoubleValue(headerRowFile.getColumnPosition(CLIENT_PRICE_COLUMN));
        Double corporativePrice = importRowFile.getDoubleValue(headerRowFile.getColumnPosition(CORPORATIVE_PRICE_COLUMN));
        Double oficialPrice = importRowFile.getDoubleValue(headerRowFile.getColumnPosition(OFICIAL_PRICE_COLUMN));
        Integer maximumCapacity = importRowFile.getIntegerValue(headerRowFile.getColumnPosition(MAXIMUM_CAPACITY_COLUMN));
        String name = importRowFile.getStringValue(headerRowFile.getColumnPosition(NAME_COLUMN));
		String roomDescription = importRowFile.getStringValue(headerRowFile.getColumnPosition(DESCRIPTION_COLUMN));

        Room room = new Room();
        room.setClientPrice(clientPrice);
        room.setCorporativePrice(corporativePrice);
        room.setMaximumCapacity(maximumCapacity);
        room.setOficialPrice(oficialPrice);
        room.setName(name);
        room.setDescription(roomDescription);
        return room;
    }

    public String[] getHeaderColumnsNames(){
        return new String[] {CLIENT_PRICE_COLUMN,
                                            CORPORATIVE_PRICE_COLUMN,
                                            OFICIAL_PRICE_COLUMN,
                                            MAXIMUM_CAPACITY_COLUMN,
                                            NAME_COLUMN,
                                            DESCRIPTION_COLUMN
           };
    }
}